<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../static/css/index.less"/>
    {#
    <link rel="stylesheet/less" href="../../static/admin/css/user_huafen_record.less"/>
    #}
    <link rel="stylesheet" href="../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <SCRIPT language=javascript src="../../static/layer/layer.js"></SCRIPT>
    <script src="../../../static/js/ajaxfileupload.js"></script>

</head>
<style>
    .js_w {
        width: 40px;
        height: 25px;
        font-size: 12px;
        line-height: 25px;
    }

    .ll {
        width: 40px;
        height: 25px;
        font-size: 12px;
        line-height: 25px;
    }

    .newadd label {
        padding: 10px 0;
        display: block;
        text-align: left;
    }

    .newadd label .adtitle {
        display: inline-block;
        width: 6rem;
        text-align: right;
        padding-right: 2%;
    }

    .newadd label span {
        text-align: right;
        padding-right: 2%;
    }

    .newadd input {
        padding: 0 10px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .newadd select {
        text-align: left;
        padding: 0 5px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .subbtn {
        margin-left: 5%;
        padding: 2px 3px;
    }

    .selectTransverse {
        display: inline-block;
    }

    .selectTransverse select {
        width: 30%;
    }
</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}


<div id="box" class="fl">
    <div class="content" style="height: 100%">
        <div class="content">
            <div class="righthead clearfix">
                <h3 class="title fl" style="color:  #3D89CB">编辑会员</h3>
            </div>
            <div class="newadd">

                <label>
                    <span class="adtitle">OPENID</span>
                    <input readonly type="text" id="storeName" class="create"
                           value="{{ res.wxOpenId | default('', true) }}">
                </label>
                <label>
                    <span class="adtitle">昵称</span>
                    <input type="text" id="wxNickName" class="create" value="{{ res.wxNickName | default('', true) }}">
                </label>
                <label>
                    <span class="adtitle">手机号码</span>
                    <input type="text" id="phone" class="create" value="{{ res.phone | default('', true) }}">
                </label>
                <label style="display: none">
                    <span class="adtitle">剩余洗车次数</span>
                    <input id="washNum" type="number" value="{{ res.washNum | default(0, true) }}" />
                </label>
                <label>
                    <span class="adtitle">绑定车牌数</span>
                    <span>{{ res.user_cp | default('0', true) }}</span>
                </label>
                <label>
                    <span class="adtitle">绑定商家</span>
                    <select class="adtitle" id="bid" style="width: 200px">
                        {% if res.bid !=0 %}
                            <option value="{{ res.bid }}">{{ res.nickname }}</option>
                        {% else %}
                            <option value="0">请选择一个商户</option>
                        {% endif %}
                        {% if result %}
                            {% for data in result %}
                                <option value="{{ data.bid }}">{{ data.nickname }}</option>
                            {% endfor %}
                        {% endif %}

                    </select>
                </label>
                <label>
                    <span class="adtitle">注册时间</span>
                    <input readonly type="text" id="addTime" class="create"
                           value="{{ res.addTime | default('', true) }}">
                </label>
                <button onclick="edit()" class="subbtn"
                        style="width: 60px;height: 30px;margin-left: 200px;background-color: #3D89CB;float: left">提交
                </button>
            </div>
        </div>
    </div>
</div>
<script src="../../../static/js/distpicker.data.js"></script>
<script src="../../../static/js/distpicker.js"></script>
</body>
</html>
<script>
    layui.use('element', function () {
        var element = layui.element;
    });
    $('#bid').on('change', function () {
        var content = $('#bid option:selected').text()
        var bid = $("#bid option:selected").val();
        if (bid != 0) {
            layer.msg("您选择绑定商家为" + content, {time: 2000}, function () {

            });
        }
    })
    function edit() {
        var phone = $('#phone').val();
        if(phone!="") {
            let myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(14[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
            if (!myreg.test(phone)) {
                layer.msg("请输入正确的手机号")
                return false
            }
        }
        layer.open({
            content: '你确定修改资料',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                var uid = {{ res.uid }};
                $.ajax({
                    url: '/admin/user_edit_post',
                    type: 'post',
                    data: {
                        'uid': uid,
                        'phone': phone,
                        'plateNum': $('#plateNum').val(),
                        'washNum': $('#washNum').val(),
                        'bid': $('#bid option:selected').val()
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                location.href = "/admin/user_list.html";
                            });
                        } else {
                            layer.msg("修改失败", {time: 2000}, function () {
                                location.href = document.referrer;
                            });
                        }
                    }
                });
            }
        });
    }


</script>